package com.niit.project.controller;

import com.niit.project.entity.BadGoods;
import com.niit.project.service.BadGoodsService;
import com.niit.project.service.impl.BadGoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

//付靖雯——用户违禁商品举报功能
@WebServlet(name = "ReportBadGoodsController", value = "/ReportBadGoodsController")
public class ReportBadGoodsController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收前端传来的数据
        String goodname = request.getParameter("goodname");
        String goodtype = request.getParameter("goodtype");
        String changemedium = request.getParameter("changemedium");
        String changeway = request.getParameter("changeway");
        //将接收到的数据存入badGoods对象中
        BadGoods badGoods = new BadGoods(goodname,goodtype,changemedium,changeway);
        BadGoodsService badGoodsService = new BadGoodsServiceImpl();
        //调用举报商品的添加方法,将被举报商品的信息存入被举报商品的列表中
        badGoodsService.addGoods(badGoods);
        System.out.println("举报成功！");
        response.sendRedirect(request.getContextPath()+"/UserGoodsListController");
    }
}
